package org.reborn.engine.render.texture

import java.nio.Buffer
import javax.media.opengl.{GL,GL2GL3}

trait Tex1D{
  self: TextureMetadata =>
  val glTarget:Int = GL2GL3.GL_TEXTURE_1D
  val texDimensions:Int = 1
  var width:Int = 0
}

class Texture1DMetadata extends Tex1D with BaseTextureMetadata 

/**
 * Create a new OpenGL texture. Requires at least GL2GL3 profile.
 * @param metadata The Texture1DMetadata associated with this texture
 */
class Texture1D(val metadata:Texture1DMetadata) extends Texture {

  protected def setImageData(gl: GL, images: Seq[Buffer], glFormat:Int, glType: Int): Unit = {
	val gl2gl3 = gl.getGL2GL3
	
	var level = 0
	while(level < images.size){
	  val imgData = images(level)
	  imgData.rewind
	  
	  gl2gl3.glTexImage1D(
  	 		  metadata.glTarget,			//The texture target of this texture (1D)
	 		  level,						//The mip-map level of the texture
	 		  metadata.glInternalFormat,	//The format that OpenGL will use to store the texture in video memory
	 		  metadata.width,				//Width of the image in pixels
	 		  0,							//Width of the border
	 		  glFormat,						//The OpenGL format if the data in the image buffer
	 		  glType,						//The OpenGL type of data in the image buffer
	 		  imgData)						//The buffer that holds the image data

	  level += 1
	}
  }

}